package com.kaiwukj.android.ufamily.mvp.ui.page.home.mall;

import android.graphics.Bitmap;
import android.os.Bundle;
import android.webkit.WebView;

import com.kaiwukj.android.ufamily.R;
import com.kaiwukj.android.ufamily.app.base.review.BaseFragment;
import com.kaiwukj.android.ufamily.app.constant.Constant;
import com.kaiwukj.android.ufamily.mvp.ui.widget.home.ShopWebView;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;

import butterknife.BindView;

public class MallContainerFragment extends BaseFragment {
    /*
        @BindView(R.id.container_left)
        ViewGroup containerLeft;
        @BindView(R.id.tv_title)
        TextView tvTitle;*/
    @BindView(R.id.web)
    ShopWebView mWebView;
    @BindView(R.id.refresh_layout)
    SmartRefreshLayout refreshLayout;


    public static MallContainerFragment newInstance() {
        return new MallContainerFragment();
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_mall;
    }

    @Override
    protected void initView() {
        // setPaddingTop(R.id.container_header);
        /*containerLeft.setVisibility(View.GONE);
        tvTitle.setText("商超");*/
    }

    @Override
    protected void initData(Bundle savedInstanceState) {
        String url = Constant.isDev ? "http://shopjoinh5test.jiayuanli.net/shopJoin.html" : "http://shopjoinh5.jiayuanli.net/shopJoin.html";
        mWebView.loadUrl(url);
        mWebView.addOnPageStateListener(new ShopWebView.onPageStateListener() {
            @Override
            public void onPageStarted(WebView view, String url, Bitmap favicon) {

            }

            @Override
            public void onPageFinished(WebView view, String url) {
              /*  if (mWebView != null) {
                    mWebView.setToken();
                }*/
                refreshLayout.finishRefresh(true);
            }
        });
    /*    mWebView.setOnMallListener(new ShopWebView.OnMallListener() {

            @Override
            public String getToken() {
                return null;
            }

            @Override
            public void goBack() {

            }
        });*/

        refreshLayout.setOnRefreshListener(layout -> {
            mWebView.reload();
        });
    }
}
